package com.eascs.fp.applyLoan.server.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.fp.applyLoan.dao.ApplyLoanDao;
import com.eascs.fp.applyLoan.server.ApplyLoanService;
import com.eascs.fp.common.entity.ApplyLoanEntity;
import com.eascs.fp.common.entity.ApplyStoreEntity;
import com.eascs.fp.common.vo.ModelResult;

@Service
public class ApplyLoanServiceImpl implements ApplyLoanService{
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private ApplyLoanDao applyLoanDao;


	@Override
	@Transactional(transactionManager = "transactionManager")
	public ModelResult<Boolean> applyLoan(ApplyLoanEntity applyLoan, ApplyStoreEntity applyStore) {
		ModelResult<Boolean> modelResult=new ModelResult<>();
		ApplyLoanEntity applyLoanModel=applyLoanDao.insertApplyLoanEntity(applyLoan);
		if (applyLoanModel == null) {
			logger.info("applyLoan.error.insertApplyLoanEntity,exception:{}");
			//return modelResult.withError("applyLoan.error.insertApplyLoanEntity", "申请贷款表插入失败");
			throw new RuntimeException("申请贷款表插入失败"); // 回滚事物
		}
		applyStore.setApplyerId(applyLoanModel.getId());
		ApplyStoreEntity applyStoreModel=applyLoanDao.insertApplyStoreEntity(applyStore);
		if (applyStoreModel == null) {
			logger.info("applyLoan.error.insertApplyStoreEntity,exception:{}");
			//return modelResult.withError("applyLoan.error.insertApplyStoreEntity", "申请贷款门店信息表插入失败");
			throw new RuntimeException("申请贷款门店信息表插入失败"); // 回滚事物
		}
		modelResult.withModel(true);
		return modelResult;
		//logger.info("member.error.insertMemberEntity(),exception:{}", e.getMessage());
//		return modelResult.withError("member.error.insertMemberEntity()", "插入失败!");
	}

}
